package com.typhoon.springboot_demo1.util;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.swing.tree.RowMapper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractCommonDao<E,K> implements CommonDao<E, K> {
	
	//private JdbcOperations jdbcTemplate;
	
	private String tableName;
	
	private Class<E> entityClass;
	
	protected static final String select = "select ";
	protected static final String from = " from ";
	protected static final String where = " where ";
	protected static final String and = " and ";
	protected static final String orderBy = " order by ";
	protected static final String oneEqOne = " 1=1 ";
	protected static final String count = " count ";
	protected static final String sum = " sum ";
	protected static final String allSymbol = "(*) ";
	protected static final String seqId = "seqId";
	protected static final String star = " * ";
	protected static final String primaryKey = " id ";
	protected static Logger log = LoggerFactory.getLogger(AbstractCommonDao.class);
	
	public AbstractCommonDao() {
		super();
		init();
	}
	
	public abstract void init();
	
	@Override
	public E queryByPrimaryKey(K k,Class<E> clazz) {
		
		
		StringBuilder sql = new StringBuilder(select);
		sql.append(star);
		sql.append(from);
		sql.append(tableName);
		sql.append(where);
		sql.append(primaryKey).append(" = ").append(k);
		Map<String,Object> map = new HashMap<>(2);
		map.put("id", 1);
		map.put("payChannel",2 );
		return null;
//		Map<String,Object> map = this.jdbcTemplate.queryForMap(sql.toString());
//		return RegUtil.mapToObject(map,entityClass);
	}
	
//	class LocalRowMapper implements RowMapper<E> {
//
//		@Override
//		public E mapRow(ResultSet rs, int rowNum) throws SQLException {
//			//RegUtil.
//			return null;
//		}
//		
//	}

//	public  void setJdbcTemplate(JdbcOperations jdbcTemplate) {
//		this.jdbcTemplate = jdbcTemplate;
//	};

	public  void setTableName(String tableName){
		this.tableName = tableName;
	};

	public  void setEntityClass(Class<E> entityClass){
		this.entityClass = entityClass;
	};
	
	
}
